The Python SDK has the capability to operate on files and folders shared with a user via shared link.

Simply use client.with_shared_link() to get a client instance that can access the shared resource.


In [1]:
from boxsdk import Client, OAuth2
# Create an SDK client using a developer token
client = Client(OAuth2(None, None, access_token='KoquazbCU7fxrMM0wSgGiAlWKZNeQGgq'))

In [2]:
# This is a shared link created with a different Box account
SHARED_LINK_URL = 'https://app.box.com/s/gjkefibtegdn318xqnsu3koc35qt18z3'

In [4]:
shared_item = client.get_shared_item(SHARED_LINK_URL)
shared_item.name


Out[4]:
u'Book1.xls'

In [6]:
# This account doesn't actually have permissions on this file outside of the shared link context
client.file(shared_item.id).get()


---------------------------------------------------------------------------
BoxAPIException                           Traceback (most recent call last)
<ipython-input-6-8b1c12239ca7> in <module>()
      1 # This account doesn't actually have permissions on this file outside of the shared link context
----> 2 client.file(shared_item.id).get()

/Users/jmeadows/.virtualenvs/sdknotebooks/lib/python2.7/site-packages/boxsdk/object/item.pyc in get(self, fields, etag)
    124         # pylint:disable=arguments-differ
    125         headers = {'If-None-Match': etag} if etag is not None else None
--> 126         return super(Item, self).get(fields=fields, headers=headers)
    127 
    128     def copy(self, parent_folder):

/Users/jmeadows/.virtualenvs/sdknotebooks/lib/python2.7/site-packages/boxsdk/object/base_object.pyc in get(self, fields, headers)
    103         url = self.get_url()
    104         params = {'fields': ','.join(fields)} if fields else None
--> 105         box_response = self._session.get(url, params=params, headers=headers)
    106         return self.__class__(self._session, self._object_id, box_response.json())
    107 

/Users/jmeadows/.virtualenvs/sdknotebooks/lib/python2.7/site-packages/boxsdk/session/box_session.pyc in get(self, url, **kwargs)
    370             `unicode`
    371         """
--> 372         response = self._prepare_and_send_request('GET', url, **kwargs)
    373         return BoxResponse(response)
    374 

/Users/jmeadows/.virtualenvs/sdknotebooks/lib/python2.7/site-packages/boxsdk/session/box_session.pyc in _prepare_and_send_request(self, method, url, headers, auto_session_renewal, expect_json_response, attempt_number, **kwargs)
    274             attempt_number,
    275             file_stream_positions=file_stream_positions,
--> 276             **kwargs
    277         )
    278 

/Users/jmeadows/.virtualenvs/sdknotebooks/lib/python2.7/site-packages/boxsdk/session/box_session.pyc in _make_request(self, method, url, headers, auto_session_renewal, expect_json_response, attempt_number, **kwargs)
    358         )
    359 
--> 360         self._raise_on_unsuccessful_request(network_response, expect_json_response, method, url)
    361 
    362         return network_response

/Users/jmeadows/.virtualenvs/sdknotebooks/lib/python2.7/site-packages/boxsdk/session/box_session.pyc in _raise_on_unsuccessful_request(self, network_response, expect_json_response, method, url)
    213                 url=url,
    214                 method=method,
--> 215                 context_info=response_json.get('context_info', None),
    216             )
    217         if expect_json_response and not self._is_json_response(network_response):

BoxAPIException: 
Message: Not Found
Status: 404
Code: not_found
Request id: 135510722156675a3fa6c6c
Headers: {'Content-Length': '242', 'Content-Encoding': 'gzip', 'Age': '0', 'Vary': 'Accept-Encoding', 'Server': 'ATS', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache, no-store', 'Date': 'Tue, 08 Dec 2015 22:31:27 GMT', 'Content-Type': 'application/json'}
URL: https://api.box.com/2.0/files/39001292145
Method: GET
Context info: {u'errors': [{u'reason': u'invalid_parameter', u'message': u"Invalid value 'f_39001292145'. 'item' with value 'f_39001292145' not found", u'name': u'item'}]}

In [7]:
# Operations on the item are allowed using client.get_shared_item() or client.with_shared_item()
client.with_shared_link(SHARED_LINK_URL, None).file(shared_item.id).get()


Out[7]:
<boxsdk.object.file.File at 0x10712db90>